package com.yjc.rabbitmq.springboot_rabbitmq.controller;

import com.yjc.rabbitmq.springboot_rabbitmq.config.ConfirmConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shkstart
 * @create 2022-08-03 12:40
 */
@Slf4j
@RestController
public class ProductController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/confirm/sendMsg/{msg}")
    public void sendMsg(@PathVariable("msg") String msg) {
        CorrelationData correlationData1 = new CorrelationData("1");
        rabbitTemplate.convertAndSend(ConfirmConfig.CONFIRM_EXCHANGE, ConfirmConfig.CONFIRM_ROUTINGKEY, msg + "key1", correlationData1);
        log.info("发送消息为：{}", msg + "key1");

        //////////////////////////////////////////////////////////

        CorrelationData correlationData2 = new CorrelationData("2");
        rabbitTemplate.convertAndSend(ConfirmConfig.CONFIRM_EXCHANGE, ConfirmConfig.CONFIRM_ROUTINGKEY + "2", msg + "key12", correlationData2);
        log.info("发送消息为：{}", msg + "key12");
    }
}
